package cn.jbolt.ai.klb.controller;

import cn.jbolt.ai.klb.entity.AiDoc;
import cn.jbolt.ai.klb.service.AiDocService;
import cn.jbolt.ai.klb.vo.GenerateQuestionVo;
import cn.jbolt.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AI文档管理
 */
@Controller
@ResponseBody
@RequestMapping("/aiDoc")
@Tag(name = "AiDoc管理Controller")
public class AiDocController {

    @Autowired
    private AiDocService docService;

    @Operation(summary = "根据ID获取文档信息", description = "根据ID获取文档信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {
        return docService.getDocById(id);
    }

    @Operation(summary = "分页获取所有文档信息", description = "dataType训练类型:1:自定义文本,2:文件块," +
            "status文件状态")
    @GetMapping("/list")
    public Result listByPage(
             Integer page,
            Integer pageSize,
            @RequestParam(required = false) String keywords,
            @RequestParam(required = false) Long knowledgeBaseId,
            @RequestParam(required = false) String dataType,
            @RequestParam(required = false) Integer status) {
        return docService.listByPage(page, pageSize, keywords, knowledgeBaseId, dataType, status);
    }
    @Operation(summary = "获取当前片段所生的问题列表")
    @GetMapping("/getQuestionListByLinkId")
    public Result getQuestionListByLinkId(Long docId) {
        return docService.getQuestionListByLinkId(docId);
    }

    @Operation(summary = "添加新的文档", description = "添加新的文档")
    @PostMapping("/add")
    public Result add(@RequestBody AiDoc doc) {
        return docService.add(doc);
    }

    @Operation(summary = "根据单个doc生成问题并保存", description = "根据单个doc生成问题并保存")
    @PostMapping("/addQuestionByDocId")
    public Result addQuestionByDocId( @RequestBody  AiDoc  doc) {
        return docService.addQuestionByDocId(doc);
    }



    @Operation(summary = "更新文档信息", description = "更新文档信息")
    @PostMapping("/update")
    public Result update(@RequestBody AiDoc doc) {
        return docService.update(doc);
    }

    @Operation(summary = "删除文档", description = "删除文档")
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        return docService.delete(id);


    }


    @Operation(summary = "获取数据类型下拉选列表", description = "获取数据类型下拉选列表")
    @GetMapping("/getDataTypeList")
    public Result getDataTypeList() {
        return docService.getDataTypeList();
    }

    @Operation(summary = "让AI根据内容生成问题", description = "让AI根据内容生成问题")
    @PostMapping("/generateQuestionByModel")
    public Result generateQuestionByModel(@RequestBody GenerateQuestionVo vo) {
        return docService.generateQuestionByModel(vo.getModelSn(), vo.getContent(), vo.getDoc());
    }

}
